package com.yeswater.multithread.chapter1.test1_11.test3;

/**
 * author : yeswater
 * date : 2023/10/18
 */

public class MyThread extends Thread{
    @Override
    public void run() {
        try {
            while (true) {
                if (this.isInterrupted()) {
                    throw new InterruptedException(" 线程被中断! ");
                }

                for (int i = 0; i < 10000; i++) {
                    new String("" + Math.random());
                }

                Box.list1.add(" 生产数据 A");
                System.out.println("list1 size=" + Box.list1.size());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        try {
            while (true) {
                if (this.isInterrupted()) {
                    throw new InterruptedException(" 线程被中断! ");
                }

                // 模拟执行任务的耗时
                for (int i = 0; i < 10000; i++) {
                    new String("" + Math.random());
                }

                Box.list2.add(" 生产数据 B");
                System.out.println("list2 size=" + Box.list2.size());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
